const { Router } = require('express')
const JWT = require("jsonwebtoken")
const User = require("../model/User")
const uploadAvatar = require("../multer/upload")

// 引入配置好的 multerConfig
const multerConfig = require('../multer/multerConfig')

// 上传到服务器地址
const BaseURL = 'http://localhost:2233'
// 上传到服务器的目录
const imgPath = '/public/'

// 创建路由对象
const router = new Router()

// 设置路由
router.post('/avatar', async (req, res) => {
  const { userId, username } = req.body
  console.log(req.body);
  // 头像图片上传
  try {
    const uploadRes = await uploadAvatar(req, res)
    console.log(uploadRes);//图片路径
    res.send({
      meta: { code: 200, msg: '上传成功！' },
      data: { img_url: uploadRes }
    })
  } catch (error) {
    res.send(error)
  }

})


module.exports = router
